app.directive('compareTo', [
    '$timeout',
    function($timeout) {
        return {
            require: 'ngModel',
            scope: {
                otherModelValue: '=compareTo'
            },
            link: function(scope, element, attributes, ngModel) {
                ngModel.$validators.compareTo = function(modelValue) {
                    $timeout(function() {
                        scope.$apply();
                    }, 500);
                    return modelValue === scope.otherModelValue;
                };
                scope.$watch('otherModelValue', function() {
                    ngModel.$validate();
                });
            }
        };
    }
]);

app.directive('keyboardHandler', [
    '$window',
    function($window) {
        return {
            restrict: 'A',
            link: function(scope, element, attrs) {
                angular.element($window).bind('native.keyboardshow', function() {
                    element.addClass('tabs-item-hide');
                });
                angular.element($window).bind('native.keyboardhide', function() {
                    element.removeClass('tabs-item-hide');
                });
            }
        };
    }
]);

app.directive('contentHandler', [
    '$rootScope', '$window', '$timeout',
    function($rootScope, $window, $timeout) {
        return {
            restrict: "EA",
            link: function(scope, element, attrs) {
                $rootScope.$on('$ionicView.beforeEnter', function(a, b) {
                    element.addClass('content-hide');
                });
                $rootScope.$on('$ionicView.afterEnter', function(a, b) {
                    $timeout(function() {
                        element.removeClass('content-hide');
                    }, 33);
                });
            }
        };
    }
]);

app.directive('setHeader', [
    function() {
        return {
            restrict: 'EA',
            link: function($scope, $element, $attr) {
                var header;
                header = document.getElementsByClassName('sub_header')[0].offsetHeight + 3;
                $element[0].style.top = header + 'px';
            }
        };
    }
]);

app.directive('noMessage', [
    '$timeout',
    function($timeout) {
        return {
            restrict: 'EA',
            scope: {
                title: '=title',
                subTitle: '=subTitle',
                icon: '=icon',
                array: '=array'
            },
            template: '<div class="text-center no_message" ng-if="isNoMessage" style="padding:60px 0px;"> <div class="icon icon-{{icon}}"></div> <h4>{{title}}</h4> <p>{{subTitle}}</p> </div>',
            link: function($scope, $element, $attributes) {
                $scope.isNoMessage = false;
                if (!$scope.icon) {
                    $scope.icon = 'bell';
                }
                $scope.$on('scroll.refreshComplete', function() {
                    $scope.$watch('array', function(array, old) {
                        if (array && array.length !== 0) {
                            $scope.isNoMessage = false;
                        } else {
                            if (array !== void 0 || (array && array.length !== 0)) {
                                $scope.isNoMessage = true;
                            }
                        }
                    });
                });
            }
        };
    }
]);

app.directive('keyboardHandler', [
    '$window',
    function($window) {
        return {
            restrict: 'A',
            link: function(scope, element, attrs) {
                angular.element($window).bind('native.keyboardshow', function() {
                    element.addClass('tabs-item-hide');
                });
                angular.element($window).bind('native.keyboardhide', function() {
                    element.removeClass('tabs-item-hide');
                });
            }
        };
    }
]);

app.directive('countDown', [
    'httpService', '$interval', 'loading',
    function(httpService, $interval, loading) {
        return {
            restrict: 'EA',
            scope: {
                tel: '=tel'
            },
            replace: true,
            template: '<a class="button f_8 c_6" ng-disabled="isabled" ng-bind="isabled ? count_down_time: \'获取验证码\'"></a>',
            link: function($scope, $element, $attr, ngModel) {
                var countDown;
                $scope.count_down_time = interval;
                $scope.isabled = false;
                countDown = function() {
                    var timer;
                    $scope.isabled = true;
                    timer = $interval((function() {
                        $scope.count_down_time -= 1;
                        if ($scope.count_down_time <= 0) {
                            $interval.cancel(timer);
                            $scope.count_down_time = interval;
                            $scope.isabled = false;
                        }
                    }), 1000);
                };
                $scope.getCode = function(tel) {
                    if (tel) {
                        if ($scope.isabled) {
                            loading.prompt('请耐心等待验证码');
                        }
                        httpService.query('accountCenter/verificationCode', {
                            telephone: tel
                        }).then(function(res) {
                            if (parseInt(res.code) === 200) {
                                countDown();
                            } else {
                                loading.prompt(res.data.msg);
                            }
                        });
                    } else {
                        loading.prompt('请输入有效的手机号码！');
                    }
                };
                angular.element($element).on('click tap', function() {
                    $scope.getCode($scope.tel);
                });
            }
        };
    }
]);

app.directive("imgCache", [
    "FileService", "$timeout", "$filter",
    function(FileService, $timeout, $filter) {
        return {
            restrict: "A",
            scope: {
                name: "=name",
                type: "=type"
            },
            link: function(scope, element, attr) {
                var fileUrl;
                element.attr("src", $filter("IMG")(scope.type));
                $timeout(function() {
                    scope.$apply();
                });
                fileUrl = void 0;
                if (ionic.Platform.isIOS() && cordova.file) {
                    fileUrl = cordova.file.documentsDirectory;
                }
                if (ionic.Platform.isAndroid() && cordova.file) {
                    fileUrl = cordova.file.dataDirectory;
                }
                scope.$watch("name", function(data) {
                    var imageName;
                    if (data) {
                        if (data.length > 100) {
                            element.attr("src", "data:image/jpeg;base64," + data);
                            $timeout(function() {
                                scope.$apply();
                            });
                        }
                        imageName = data.substring(data.lastIndexOf("/") + 1, data.length);
                        FileService.query(imageName, data, fileUrl).then(function(res) {
                            element.attr("src", res.data);
                            $timeout(function() {
                                scope.$apply();
                            });
                        });
                    }
                });
            }
        };
    }
]);

//年龄验证
app.directive('inputFormat', [
    function() {
        return {
            require: '?ngModel',
            link: function(scope, element, attr, ngModel) {
                var len;
                if (!ngModel) {
                    return;
                }
                len = 4;
                scope.$watch(function() {
                    return ngModel.$viewValue;
                }, function(value) {
                    if (value) {
                        ngModel.$setViewValue(value.replace(/[^\d.]/g, '').substr(0, len));
                        ngModel.$render();
                    }
                });
            }
        };
    }
]);

app.factory("FileService", [
    "$q", "$cordovaFile", "$cordovaFileTransfer", "$timeout", "$cordovaNetwork",
    function($q, $cordovaFile, $cordovaFileTransfer, $timeout, $cordovaNetwork) {
        var CheckThenDownloadFile;
        CheckThenDownloadFile = function(imageName, url, fileUrl) {
            var q;
            q = $q.defer();
            $cordovaFile.checkFile(fileUrl, imageName + ".png").then((function(success) {
                q.resolve({
                    data: success.nativeURL
                });
            }), function(error) {
                var nativeURL, targetPath;
                if ($cordovaNetwork.isOnline()) {
                    targetPath = fileUrl + imageName + ".png";
                    nativeURL = '';
                    $cordovaFileTransfer.download(url, targetPath, {}, true).then(function(result) {
                        nativeURL = result.nativeURL;
                    }, function(err) {
                        q.resolve({
                            data: url
                        });
                    }, function(progress) {
                        $timeout(function() {
                            if (angular.equals(progress.loaded, progress.total)) {
                                q.resolve({
                                    data: nativeURL
                                });
                            }
                        });
                    });
                } else {
                    q.reject({
                        data: "./img/mine/iconfont-moretouxiang.png"
                    });
                }
            });
            return q.promise;
        };
        return {
            query: CheckThenDownloadFile
        };
    }
]);

app.directive('ngEnter', [
    function() {
        return function(scope, element, attrs) {
            element.bind('keydown keypress', function(event) {
                if (event.keyCode === 13) {
                    scope.$apply(function() {
                        scope.$eval(attrs.ngEnter);
                    });
                    event.preventDefault();
                }
            });
        };
    }
]);

app.directive('calendar', [
    '$ionicPopover', '$timeout',
    function($ionicPopover, $timeout) {
        return {
            restrict: 'A',
            scope: {
                calendartimedate: '=calendarTime',
                istrue: ' = trueLink',
                istruebehind: ' = istrueBehind ',
                submitCallback: '&'
            },
            replace: true,
            template: ['<div ng-click="openPopover($event);" ng-tap="openPopover($event);">{{miao | date: "yyyy  年  MM  月  dd    日"}}</div>'].join(''),
            link: function(scope, element, attr) {
                var month_31;
                scope.lastMonth = [];
                scope.nextMonth = [];
                scope.thisMonth = [];
                month_31 = [1, 3, 5, 7, 8, 10, 12];
                scope.month = function(thisYear, thisMouth) {
                    var days, mouth, year;
                    year = thisYear;
                    mouth = thisMouth;
                    days = void 0;
                    if (mouth === 2) {
                        days = (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0 ? 29 : 28;
                    } else if (month_31.indexOf(mouth) !== -1) {
                        days = 31;
                    } else {
                        days = 30;
                    }
                    return days;
                };
                scope.calendarTimeMethods = function(years, month) {
                    var b, c, i, lastMonthB, res, yearsB;
                    res = scope.month(years, month);
                    i = 1;
                    c = 0;
                    b = 1;
                    yearsB = void 0;
                    lastMonthB = void 0;
                    scope.lastMonth = [];
                    scope.thisMonth = [];
                    scope.nextMonth = [];
                    while (i <= res) {
                        scope.thisMonth.push(i);
                        i++;
                    }
                    scope.day = new Date(years + '/' + month + '/1').getDay();
                    if (month === 1) {
                        lastMonthB = 12;
                        yearsB = years - 1;
                    } else {
                        lastMonthB = month - 1;
                        yearsB = years;
                    }
                    scope.lastDay = scope.month(yearsB, lastMonthB);
                    while (c < scope.day) {
                        scope.lastMonth.push(scope.lastDay);
                        scope.lastDay--;
                        c++;
                    }
                    scope.lastMonth = scope.lastMonth.reverse();
                    scope.nextDay = new Date(years + '/' + month + '/' + res).getDay();
                    while (b <= 42 - res - scope.lastMonth.length) {
                        scope.nextMonth.push(b);
                        b++;
                    }
                };
                scope.lastYearsMethods = function() {
                    var id;
                    scope.yearsDate--;
                    scope.lastMonth = [];
                    scope.nextMonth = [];
                    scope.thisMonth = [];
                    id = scope.month(scope.yearsDate, scope.monthDate);
                    if (id < scope.selectid + 1) {
                        scope.selectid = id - 1;
                    }
                    if (scope.istrue) {
                        if (scope.yearsDate <= (new Date).getFullYear()) {
                            scope.yearsDateTrue = true;
                            scope.yearsDate = (new Date).getFullYear();
                            if (scope.monthDate <= (new Date).getMonth() + 1) {
                                scope.monthDate = (new Date).getMonth() + 1;
                                scope.monthDateTrue = true;
                                if (scope.selectid <= (new Date).getDate() - 1) {
                                    scope.selectid = (new Date).getDate() - 1;
                                    scope.selectTrue = true;
                                    scope.selectWhether = (new Date).getDate() - 1;
                                }
                            }
                        }
                    }
                    if (scope.istruebehind) {
                        scope.yearsDatehou = false;
                        scope.monthDatehou = false;
                        scope.selectTruehou = false;
                        scope.selectHou = 32;
                    }
                    scope.calendarTimeMethods(scope.yearsDate, scope.monthDate);
                };
                scope.nextYearsMethods = function() {
                    var id;
                    scope.yearsDate++;
                    scope.lastMonth = [];
                    scope.nextMonth = [];
                    scope.thisMonth = [];
                    id = scope.month(scope.yearsDate, scope.monthDate);
                    if (id < scope.selectid + 1) {
                        scope.selectid = id - 1;
                    }
                    scope.calendarTimeMethods(scope.yearsDate, scope.monthDate);
                    if (scope.istrue) {
                        scope.yearsDateTrue = false;
                        scope.monthDateTrue = false;
                        scope.selectTrue = false;
                        scope.selectWhether = -1;
                    }
                    if (scope.istruebehind) {
                        if (scope.yearsDate >= (new Date).getFullYear()) {
                            scope.yearsDatehou = true;
                            scope.yearsDate = (new Date).getFullYear();
                            if (scope.monthDate >= (new Date).getMonth() + 1) {
                                scope.monthDate = (new Date).getMonth() + 1;
                                scope.monthDatehou = true;
                                if (scope.selectid >= (new Date).getDate() - 1) {
                                    scope.selectid = (new Date).getDate() - 1;
                                    scope.selectTruehou = true;
                                    scope.selectHou = scope.selectid;
                                }
                            }
                        }
                    }
                };
                scope.lastMonthMethods = function() {
                    var id;
                    if (scope.monthDate === 1) {
                        scope.yearsDate--;
                        scope.monthDate = 12;
                    } else {
                        scope.monthDate--;
                    }
                    scope.lastMonth = [];
                    scope.nextMonth = [];
                    scope.thisMonth = [];
                    id = scope.month(scope.yearsDate, scope.monthDate);
                    if (id < scope.selectid + 1) {
                        scope.selectid = id - 1;
                    }
                    if (scope.istrue) {
                        if (scope.yearsDate < (new Date).getFullYear()) {
                            scope.monthDateTrue = true;
                            return;
                        } else {
                            if (scope.yearsDate === (new Date).getFullYear()) {
                                scope.yearsDateTrue = true;
                                if (scope.monthDate <= (new Date).getMonth() + 1) {
                                    scope.monthDate = (new Date).getMonth() + 1;
                                    scope.monthDateTrue = true;
                                    scope.selectTrue = true;
                                    scope.selectWhether = (new Date).getDate() - 1;
                                    if (scope.selectid < (new Date).getDate() - 1) {
                                        scope.selectid = (new Date).getDate() - 1;
                                    }
                                }
                            }
                        }
                    }
                    if (scope.istruebehind) {
                        if (scope.yearsDate < (new Date).getFullYear()) {
                            scope.yearsDatehou = false;
                        }
                        scope.monthDatehou = false;
                        scope.selectTruehou = false;
                        scope.selectHou = 32;
                    }
                    scope.calendarTimeMethods(scope.yearsDate, scope.monthDate);
                };
                scope.nextMonthMethods = function() {
                    var id;
                    if (scope.monthDate === 12) {
                        scope.monthDate = 1;
                        scope.yearsDate++;
                        if (scope.istrue) {
                            scope.yearsDateTrue = false;
                        }
                    } else {
                        scope.monthDate++;
                        if (scope.istrue) {
                            scope.monthDateTrue = false;
                        }
                    }
                    scope.lastMonth = [];
                    scope.nextMonth = [];
                    scope.thisMonth = [];
                    id = scope.month(scope.yearsDate, scope.monthDate);
                    if (id < scope.selectid + 1) {
                        scope.selectid = id - 1;
                    }
                    if (scope.istrue) {
                        scope.monthDateTrue = false;
                        scope.selectTrue = false;
                        scope.selectWhether = -1;
                    }
                    if (scope.istruebehind) {
                        if (scope.yearsDate > (new Date).getFullYear()) {
                            scope.monthDatehou = true;
                            return;
                        } else {
                            if (scope.yearsDate === (new Date).getFullYear()) {
                                scope.yearsDatehou = true;
                                if (scope.monthDate >= (new Date).getMonth() + 1) {
                                    scope.monthDate = (new Date).getMonth() + 1;
                                    scope.monthDatehou = true;
                                    scope.selectTruehou = true;
                                    scope.selectHou = (new Date).getDate() - 1;
                                    if (scope.selectid > (new Date).getDate() - 1) {
                                        scope.selectid = (new Date).getDate(-1);
                                    }
                                }
                            } else {
                                scope.yearsDatehou = false;
                                scope.monthDatehou = false;
                            }
                        }
                    }
                    scope.calendarTimeMethods(scope.yearsDate, scope.monthDate);
                };
                scope.aboveMonth = function(lastDay) {
                    if (scope.monthDate === 1) {
                        scope.monthDate = 12;
                        scope.yearsDate--;
                    } else {
                        scope.monthDate--;
                    }
                    scope.selectid = lastDay - 1;
                    scope.lastMonth = [];
                    scope.nextMonth = [];
                    scope.thisMonth = [];
                    if (scope.istrue) {
                        if (scope.yearsDate <= (new Date).getFullYear()) {
                            scope.yearsDateTrue = true;
                            if (scope.monthDate <= (new Date).getMonth() + 1) {
                                scope.monthDateTrue = true;
                                scope.selectTrue = true;
                                scope.selectWhether = (new Date).getDate() - 1;
                            }
                        } else {
                            scope.monthDateTrue = false;
                            scope.selectWhether = -1;
                        }
                    }
                    if (scope.istruebehind) {
                        if (scope.yearsDate <= (new Date).getFullYear()) {
                            scope.yearsDatehou = true;
                            if (scope.monthDate <= (new Date).getMonth() + 1) {
                                scope.monthDatehou = false;
                                scope.selectTruehou = false;
                                scope.selectHou = 32;
                            } else {
                                scope.yearsDatehou = false;
                                scope.monthDatehou = false;
                                scope.selectTruehou = false;
                                scope.selectHou = 32;
                            }
                        } else {
                            scope.monthDatehou = false;
                        }
                    }
                    scope.calendarTimeMethods(scope.yearsDate, scope.monthDate);
                };
                scope.underMonth = function(nextDay) {
                    if (scope.monthDate === 12) {
                        scope.monthDate = 1;
                        scope.yearsDate++;
                    } else {
                        scope.monthDate++;
                    }
                    scope.selectid = nextDay - 1;
                    scope.lastMonth = [];
                    scope.nextMonth = [];
                    scope.thisMonth = [];
                    if (scope.istrue) {
                        scope.selectWhether = -1;
                        scope.selectTrue = false;
                        if (scope.yearsDate > (new Date).getFullYear()) {
                            scope.yearsDateTrue = false;
                        }
                        if (scope.monthDate > (new Date).getMonth() + 1) {
                            scope.monthDateTrue = false;
                        }
                    }
                    if (scope.istruebehind) {
                        scope.selectHou = (new Date).getDate() - 1;
                        scope.selectTruehou = true;
                        if (scope.yearsDate >= (new Date).getFullYear()) {
                            scope.yearsDatehou = true;
                            if (scope.monthDate >= (new Date).getMonth() + 1) {
                                scope.monthDatehou = true;
                                scope.selectTruehou = true;
                                scope.selectHou = new Date().getDate() - 1;
                            } else {
                                scope.selectHou = 32;
                                scope.selectTruehou = false;
                            }
                        } else {
                            scope.selectTruehou = false;
                            scope.selectHou = 32;
                        }
                    }
                    scope.calendarTimeMethods(scope.yearsDate, scope.monthDate);
                };
                scope.thisClick = function(key) {
                    scope.selectid = key;
                };
                scope.queding = function() {
                    scope.miao = new Date(scope.yearsDate + '/' + scope.monthDate + '/' + (scope.selectid + 1)).getTime();
                    scope.calendartimedate = scope.miao;
                    element.attr('calendar-time', scope.calendartimedate);
                    $timeout(function() {
                        scope.$apply();
                    });
                    scope.popover.remove();
                    $ionicPopover.fromTemplateUrl('templates/common/calendar.html', {
                        scope: scope
                    }).then(function(popover) {
                        scope.popover = popover;
                    });
                    $timeout((function() {
                        scope.submitCallback();
                    }), 500);
                };
                if (!scope.calendartimedate) {
                    scope.miao = parseInt((new Date).getTime() / 86400000) * 86400000 - 28800000;
                    scope.selectid = (new Date).getDate() - 1;
                    scope.yearsDate = (new Date).getFullYear();
                    scope.monthDate = (new Date).getMonth() + 1;
                    scope.calendarTimeMethods(scope.yearsDate, scope.monthDate);
                    scope.calendartimedate = scope.miao;
                }
                scope.$watch('calendartimedate', function(newData) {
                    if (newData) {
                        scope.miao = newData;
                        scope.selectid = new Date(newData).getDate() - 1;
                        scope.yearsDate = new Date(newData).getFullYear();
                        scope.monthDate = new Date(newData).getMonth() + 1;
                        if (scope.istrue) {
                            if (scope.yearsDate <= (new Date).getFullYear()) {
                                scope.yearsDateTrue = true;
                                if (scope.monthDate <= (new Date).getMonth() + 1) {
                                    scope.monthDateTrue = true;
                                    scope.selectWhether = new Date().getDate() - 1;
                                    scope.selectTrue = true;
                                } else {
                                    scope.selectWhether = -1;
                                    scope.selectTrue = false;
                                }
                            }
                        }
                        if (scope.istruebehind) {
                            if (scope.yearsDate >= (new Date).getFullYear()) {
                                scope.yearsDatehou = true;
                                if (scope.monthDate >= (new Date).getMonth() + 1) {
                                    scope.monthDatehou = true;
                                    scope.selectHou = new Date().getDate() - 1;
                                    scope.selectTruehou = true;
                                } else {
                                    scope.selectHou = 32;
                                    scope.selectTruehou = false;
                                }
                            }
                        }
                        scope.calendarTimeMethods(scope.yearsDate, scope.monthDate);
                    }
                });
                scope.openPopover = function($event) {
                    $ionicPopover.fromTemplateUrl('templates/common/calendar.html', {
                        scope: scope
                    }).then(function(popover) {
                        scope.popover = popover;
                        scope.popover.show($event);
                    });
                };
                scope.closePopover = function() {
                    scope.popover.hide();
                };
                scope.$on('$destroy', function() {
                    if (scope.popover) {
                        scope.popover.remove();
                    }
                });
            }
        };
    }
]);

app.directive('beforeAfter', [
    '$ionicPopover', '$timeout',
    function($ionicPopover, $timeout) {
        return {
            restrict: 'AEC',
            replace: true,
            scope: {
                state: ' = stateLine',
                timea: ' = timeaLink',
                daylink: ' = dayLink',
                hourslink: ' = hoursLink',
                submitCallback: '&'
            },
            template: ['<div ng-click="openPopover($event)">{{accordingDay}}{{accordingBefore}} {{accordingHours}}:00</div>'].join(''),
            link: function(scope, element, attr) {
                scope.hours = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23];
                scope.day = ['一天', '二天', '三天', '四天', '一周'];
                scope.beforeAfter = ['前', '后'];
                if (!scope.timea) {
                    scope.hoursSelected = 0;
                    scope.daySelected = 0;
                    scope.timea = 86400;
                } else {
                    scope.tian = parseInt(scope.timea / 86400000);
                    if (scope.tian > 4) {
                        scope.daySelected = scope.day.length - 1;
                    } else {
                        scope.daySelected = scope.tian;
                    }
                    scope.hoursSelected = 24 - parseInt((scope.timea - (parseInt(scope.timea / 86400000) * 86400000)) / 3600000);
                    if (scope.hoursSelected === 24) {
                        scope.hoursSelected = 0;
                    }
                }
                if (scope.daylink) {
                    if (scope.daylink === 7) {
                        scope.daySelected = 4;
                    } else {
                        scope.daySelected = scope.daylink - 1;
                    }
                }
                if (scope.hourslink) {
                    scope.hoursSelected = parseInt(scope.hourslink / 3600000);
                    if (scope.hoursSelected === 24) {
                        scope.hoursSelected = 0;
                    }
                }
                if (!scope.personal) {
                    if (scope.state === 0) {
                        scope.beforeSelected = 0;
                    } else {
                        scope.beforeSelected = 1;
                    }
                }
                scope.accordingHours = scope.hours[scope.hoursSelected];
                scope.accordingDay = scope.day[scope.daySelected];
                scope.accordingBefore = scope.beforeAfter[scope.beforeSelected];
                scope.openPopover = function($event) {
                    $ionicPopover.fromTemplateUrl('templates/mine/memorandum/take_detail.html', {
                        scope: scope
                    }).then(function(popover) {
                        scope.popover = popover;
                        scope.popover.show($event);
                    });
                };
                scope.closePopover = function() {
                    scope.popover.hide();
                    if (scope.daySelected === scope.day.length - 1) {
                        scope.daylink = 7;
                        scope.timea = 7 * 86400000;
                    } else {
                        scope.daylink = scope.daySelected + 1;
                        scope.timea = scope.daylink * 86400000;
                    }
                    scope.hourslink = scope.hoursSelected * 3600000;
                    if (scope.state === 0) {
                        scope.timea = scope.timea - (scope.hoursSelected * 3600000);
                    } else {
                        scope.timea = scope.timea + scope.hoursSelected * 3600000;
                    }
                    $timeout((function() {
                        scope.submitCallback();
                    }), 500);
                };
                scope.$on('$destroy', function() {
                    if (scope.popover) {
                        scope.popover.remove();
                    }
                });
                scope.beforeDay = function() {
                    if (scope.daySelected === 0) {
                        scope.daySelected = scope.day.length - 1;
                    } else {
                        scope.daySelected = scope.daySelected - 1;
                    }
                    scope.accordingDay = scope.day[scope.daySelected];
                };
                scope.afterDay = function() {
                    if (scope.daySelected === scope.day.length - 1) {
                        scope.daySelected = 0;
                    } else {
                        scope.daySelected = scope.daySelected + 1;
                    }
                    scope.accordingDay = scope.day[scope.daySelected];
                };
                scope.beforeHours = function() {
                    if (scope.hoursSelected === 0) {
                        scope.hoursSelected = scope.hours.length - 1;
                    } else {
                        scope.hoursSelected = scope.hoursSelected - 1;
                    }
                    scope.accordingHours = scope.hours[scope.hoursSelected];
                };
                scope.afterHours = function() {
                    if (scope.hoursSelected === scope.hours.length - 1) {
                        scope.hoursSelected = 0;
                    } else {
                        scope.hoursSelected = scope.hoursSelected + 1;
                    }
                    scope.accordingHours = scope.hours[scope.hoursSelected];
                };
            }
        };
    }
]);

app.directive('imgBig', [
    '$ionicPopover', '$timeout',
    function($ionicPopover, $timeout) {
        return {
            restrict: 'AEC',
            link: function(scope, element, attr) {
                var template;
                template = '<ion-popover-view class=\'amplification\'><ion-content scroll=\'false\' ng-click=\'closePopover()\'><ion-scroll zooming=\'true\' direction=\'xy\' scrollbar-x=\'false\' scrollbar-y=\'false\' min-zoom=\'1\' max-zoom=\'3\' style=\'width: 100%; height: 100%\'><img ng-src=\'{{img}}\'></ion-scroll><div class=\'icon-cuo icon-guanbi\'></div></ion-content></ion-popover-view>';
                scope.popover = $ionicPopover.fromTemplate(template, {
                    scope: scope
                });
                scope.closePopover = function() {
                    if (scope.popover) {
                        scope.popover.remove();
                    }
                    scope.popover = $ionicPopover.fromTemplate(template, {
                        scope: scope
                    });
                };
                scope.$on('$destroy', function() {
                    scope.popover.remove();
                });
                $timeout((function() {
                    element.on('click tap', function() {
                        scope.img = element[0].src;
                        scope.$apply();
                        scope.popover.show(template);
                    });
                }), 500);
            }
        };
    }
]);